home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / pygtk / 2.0 / codegen / defsparser.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2006-01-20  |  6KB  |  187 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import os
  5. import sys
  6. import scmexpr
  7. from definitions import *
  8.  
  9. class IncludeParser(scmexpr.Parser):
  10.     '''A simple parser that follows include statements automatically'''
  11.     
  12.     def include(self, filename):
  13.         if not os.path.isabs(filename):
  14.             filename = os.path.join(os.path.dirname(self.filename), filename)
  15.         
  16.         oldfile = self.filename
  17.         self.filename = filename
  18.         self.startParsing()
  19.         self.filename = oldfile
  20.  
  21.  
  22.  
  23. class DefsParser(IncludeParser):
  24.     
  25.     def __init__(self, arg, defines = { }):
  26.         IncludeParser.__init__(self, arg)
  27.         self.objects = []
  28.         self.interfaces = []
  29.         self.enums = []
  30.         self.boxes = []
  31.         self.pointers = []
  32.         self.functions = []
  33.         self.virtuals = []
  34.         self.c_name = { }
  35.         self.methods = { }
  36.         self.defines = defines
  37.  
  38.     
  39.     def define_object(self, *args):
  40.         odef = apply(ObjectDef, args)
  41.         self.objects.append(odef)
  42.         self.c_name[odef.c_name] = odef
  43.  
  44.     
  45.     def define_interface(self, *args):
  46.         idef = apply(InterfaceDef, args)
  47.         self.interfaces.append(idef)
  48.         self.c_name[idef.c_name] = idef
  49.  
  50.     
  51.     def define_enum(self, *args):
  52.         edef = apply(EnumDef, args)
  53.         self.enums.append(edef)
  54.         self.c_name[edef.c_name] = edef
  55.  
  56.     
  57.     def define_flags(self, *args):
  58.         fdef = apply(FlagsDef, args)
  59.         self.enums.append(fdef)
  60.         self.c_name[fdef.c_name] = fdef
  61.  
  62.     
  63.     def define_boxed(self, *args):
  64.         bdef = apply(BoxedDef, args)
  65.         self.boxes.append(bdef)
  66.         self.c_name[bdef.c_name] = bdef
  67.  
  68.     
  69.     def define_pointer(self, *args):
  70.         pdef = apply(PointerDef, args)
  71.         self.pointers.append(pdef)
  72.         self.c_name[pdef.c_name] = pdef
  73.  
  74.     
  75.     def define_function(self, *args):
  76.         fdef = apply(FunctionDef, args)
  77.         self.functions.append(fdef)
  78.         self.c_name[fdef.c_name] = fdef
  79.  
  80.     
  81.     def define_method(self, *args):
  82.         mdef = apply(MethodDef, args)
  83.         self.functions.append(mdef)
  84.         self.c_name[mdef.c_name] = mdef
  85.  
  86.     
  87.     def define_virtual(self, *args):
  88.         vdef = apply(VirtualDef, args)
  89.         self.virtuals.append(vdef)
  90.  
  91.     
  92.     def merge(self, old, parmerge):
  93.         for obj in self.objects:
  94.             if old.c_name.has_key(obj.c_name):
  95.                 obj.merge(old.c_name[obj.c_name])
  96.                 continue
  97.         
  98.         for f in self.functions:
  99.             if old.c_name.has_key(f.c_name):
  100.                 f.merge(old.c_name[f.c_name], parmerge)
  101.                 continue
  102.         
  103.  
  104.     
  105.     def printMissing(self, old):
  106.         for obj in self.objects:
  107.             if not old.c_name.has_key(obj.c_name):
  108.                 obj.write_defs()
  109.                 continue
  110.         
  111.         for f in self.functions:
  112.             if not old.c_name.has_key(f.c_name):
  113.                 f.write_defs()
  114.                 continue
  115.         
  116.  
  117.     
  118.     def write_defs(self, fp = sys.stdout):
  119.         for obj in self.objects:
  120.             obj.write_defs(fp)
  121.         
  122.         for enum in self.enums:
  123.             enum.write_defs(fp)
  124.         
  125.         for boxed in self.boxes:
  126.             boxed.write_defs(fp)
  127.         
  128.         for pointer in self.pointers:
  129.             pointer.write_defs(fp)
  130.         
  131.         for func in self.functions:
  132.             func.write_defs(fp)
  133.         
  134.  
  135.     
  136.     def find_object(self, c_name):
  137.         for obj in self.objects:
  138.             if obj.c_name == c_name:
  139.                 return obj
  140.                 continue
  141.         else:
  142.             raise ValueError, 'object not found'
  143.  
  144.     
  145.     def find_constructor(self, obj, overrides):
  146.         for func in self.functions:
  147.             if isinstance(func, FunctionDef) and func.is_constructor_of == obj.c_name and not overrides.is_ignored(func.c_name):
  148.                 return func
  149.                 continue
  150.         
  151.  
  152.     
  153.     def find_methods(self, obj):
  154.         objname = obj.c_name
  155.         return filter((lambda func, on = objname: if isinstance(func, MethodDef):
  156. passfunc.of_object == on), self.functions)
  157.  
  158.     
  159.     def find_virtuals(self, obj):
  160.         objname = obj.c_name
  161.         retval = filter((lambda func, on = objname: if isinstance(func, VirtualDef):
  162. passfunc.of_object == on), self.virtuals)
  163.         return retval
  164.  
  165.     
  166.     def find_functions(self):
  167.         return filter((lambda func: if isinstance(func, FunctionDef):
  168. passnot (func.is_constructor_of)), self.functions)
  169.  
  170.     
  171.     def ifdef(self, *args):
  172.         if args[0] in self.defines:
  173.             for arg in args[1:]:
  174.                 self.handle(arg)
  175.             
  176.         
  177.  
  178.     
  179.     def ifndef(self, *args):
  180.         if args[0] not in self.defines:
  181.             for arg in args[1:]:
  182.                 self.handle(arg)
  183.             
  184.         
  185.  
  186.  
  187.